//
//  JSMainViewController.swift
//  JS weibo
//
//  Created by Jackie on 16/5/19.
//  Copyright © 2016年 Jackie. All rights reserved.
//

import UIKit

class JSMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
        
        let mainTabbar = JSMainTabBar()
        
        mainTabbar.plusBtn.addTarget(self, action: #selector(JSMainViewController.plusBtnDidClick), forControlEvents: .TouchUpInside)
        print(tabBar.classForCoder)
        setValue(mainTabbar, forKey: "tabBar")
        print(tabBar.classForCoder)
    }
    
    @objc private func plusBtnDidClick() {
        print("我被点了")
    }

    private func addChildViewControllers() {
        
        addChildViewController(JSHomeTableViewController(),title:"首页",imageName:"tabbar_home")
        addChildViewController(JSMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(JSDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(JSProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

    
    private func addChildViewController(vc: UIViewController,title:String,imageName:String){
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal:0,vertical: -3)
        
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
    }
}


class person: NSObject {
    func haha() {
        let tab = JSMainViewController()
        tab.addChildViewControllers()
    }
}


